//% color=#aa278d
namespace TinyWebDB {
    //% block="TinyWebDB Init username[user] password[secret]" blockType="command"
    //% user.shadow="string"   user.defl="share"
    //% secret.shadow="string"   secret.defl="everyone"
    export function TinyWebDBInit(parameter: any, block: any){
        let user = parameter.user.code;
        let secret = parameter.secret.code;
        Generator.addImport("import urequests");
        Generator.addImport("import ujson");
        Generator.addImport("from tinywebdb import *");
        Generator.addCode(`mydb = TinyWebDB(${user},${secret})`); 
    }
	
	
	
    //% block="Count Database Records" blockType="reporter"
    export function Count(parameter: any, block: any){
        Generator.addCode(`mydb.count()`);
    }



    //% block="Get Tag[tag] Value" blockType="reporter"
    //% tag.shadow="string"   tag.defl=""
    export function Get(parameter: any, block: any){
        let tag = parameter.tag.code;
        Generator.addCode(`mydb.get(${tag})`);
    }



   //% block="Search No[startNum] count[num] tag[tag] type[showtype]" blockType="reporter"
    //% startNum.shadow="number" startNum.defl="1"
    //% num.shadow="number" num.defl="1"
    //% tag.shadow="string"   tag.defl=""
    //% showtype.shadow="dropdown" showtype.options="showtype"   showtype.defl="showtype.both"
    export function Search(parameter: any, block: any){
        let startNum = parameter.startNum.code;
        let num = parameter.num.code;
        let tag = parameter.tag.code;
        let showtype = parameter.showtype.code;
        Generator.addCode(`mydb.search(${startNum},${num},${tag},"${showtype}")`);
    }

	

    //% block="Add Tag[tag] Value[tagValue]" blockType="command"
    //% tag.shadow="string"   tag.defl=""
    //% tagValue.shadow="string"   tagValue.defl=""
    export function Add(parameter: any, block: any){
        let tag = parameter.tag.code;
        let tagValue = parameter.tagValue.code;
        Generator.addCode(`mydb.add(${tag},${tagValue})`);
    }


	
     //% block="Update Tag[tag] Value[tagValue]" blockType="command"
    //% tag.shadow="string"   tag.defl=""
    //% tagValue.shadow="string"   tagValue.defl=""
    export function Update(parameter: any, block: any){
        let tag = parameter.tag.code;
        let tagValue = parameter.tagValue.code;
        Generator.addCode(`mydb.update(${tag},${tagValue})`);
    }
	
	
	
    //% block="Delete Tag [tag] Records" blockType="command"
    //% tag.shadow="string"   tag.defl=""
    export function Delete(parameter: any, block: any){
        let tag = parameter.tag.code;
        Generator.addCode(`mydb.delete(${tag})`);
    }

}